<?php

/**
 * login actions.
 *
 * @package    ecampus
 * @subpackage login
 * @author     Grupo 608
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class loginActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $q = Doctrine_Query::create()
            ->select('a.id_usuario')
            ->from('usuario a')
            ->where('a.nombre_usuario = ?',$request->getParameter('username'))
            ->fetchOne();
//    if($q == 'A')  {$modulo = 'alumno'; }

//    $accion = 'index';
//    $modulo = 'usuario' ;
//    $this->forward($modulo, $accion);
  }
  public function executeLogin(sfWebRequest $request)
  {
      $this->form = new LoginForm();
//      $this->executePrepareLogin();
      
//      if($request->isMethod('post')){
//          $this->form->bind($request->getParameter('login'));
//          if($this->form->isValid()){
//              //autenticar el usuario y redirigirlo
//              $this->getUser()->setAuthenticated(true);
//              $this->getUser()->addCredential('user');
//              $this->redirect('usuario/index');
//          }
//      }
        sfView::SUCCESS;
  }
//  public function executePrepareLogin()
//  {
//      if($this->getRequest()->getMethod() != sfRequest::POST){
//          sfView::SUCCESS;
//      }
//      else{
//          $usr = $this->getRequestParameter('nombre_usuario');
//          $psw = $this->getRequestParameter('password');
//
////          $psw = md5($psw);
//
//          $c = new Criteria();
//          $c->add(AuthorPeer::USERNAME,$usr);
//          $c->add(AuthorPeer::PASSWORD,$psw);
//
//          $resultados = AuthorPeer::doSelect($c);
//
//          if($resultados){
//              $this->setFlash('msg','Login correcto');
//              $this->getUser()->setAuthenticated(true);
//              $this->getUser()->setAttribute('logged', true);
//
//              $this->redirect('usuario/index');
//          }
//
//      }
//  }
  public function executeLogout(sfWebRequest $request)
  {
      $this->getUser()->clearCredentials();
      $this->getUser()->setAuthenticated(false);
      $this->redirect('homepage');
  }
}
